#include "main.h"

void Initialize()
{
	//bodies = vector<RigidBody>();
	ball = Ball(10, 1);
	//board = Board();
	//schuteGuide = SquareBumper( vector3( 450, 10, 0 ), 400, 20 );
	//tbump1 = TriangleBumper( vector3( 100,500,0),vector3( 200,600,0),vector3( 300,500,0));
	//tbump2 = TriangleBumper( vector3( 420,100,0),vector3( 470,200,0),vector3( 470,100,0));

	// Create Paddles and ball
	pLeft = HingeBar(100, 20, 1);
	pRight = HingeBar(100, 20, 1);
	ball.transform.position = vector3(530, 60, 0);
	
	// Set Paddle Transform
	pLeft.transform.position = vector3(180, 100, 0);
	pLeft.transform.orientation = quaternion(0, vector3::In());
	pLeft.maxAngle = 30.0;
	pLeft.neutral = 0.0f;

	pRight.transform.position = vector3(420, 100, 0);
	pRight.transform.orientation = quaternion(pi, vector3::In());
	pRight.maxAngle = 30.0;
	pRight.neutral = 180.0;

	// Create game board colliders
	bLeft = Bar(710, 10, 1);
	bRight = Bar(600, 10, 1);
	bBase = Bar(50, 10, 1);
	bShute = Bar(550, 10, 1);
	bTopRight = Bar(111, 10, 1);
	bTop = Bar(420, 10, 1);
	bLeftGuard = Bar(140, 10, 1);
	bLeftHook = Bar(70, 10, 1);
	bRightGuard = Bar(140, 10, 1);
	bRightHook = Bar(70, 10, 1);

	// Set board colliders transform
	bLeft.transform.position = vector3(90, 400, 0);
	bLeft.transform.orientation = quaternion(pi/2, vector3::In());

	bRight.transform.position = vector3(550, 350, 0);
	bRight.transform.orientation = quaternion(pi/2, vector3::In());

	bBase.transform.position = vector3(530, 50, 0);
	bBase.transform.orientation = quaternion(0, vector3::In());

	bShute.transform.position = vector3(510, 325, 0);
	bShute.transform.orientation = quaternion(pi/2, vector3::In());

	bTopRight.transform.position = vector3(530, 700, 0);
	bTopRight.transform.orientation = quaternion(pi * 5/8, vector3::In());
	
	bTop.transform.position = vector3(300, 750, 0); 
	bTop.transform.orientation = quaternion(0, vector3::In());

	bLeftGuard.transform.position = vector3(130, 200, 0);
	bLeftGuard.transform.orientation = quaternion(pi/2, vector3::In());

	bLeftHook.transform.position = vector3(160, 115, 0);
	bLeftHook.transform.orientation = quaternion(pi/6, vector3::In() * -1.0);

	bRightGuard.transform.position = vector3(470, 200, 0);
	bRightGuard.transform.orientation = quaternion(pi/2, vector3::In());

	bRightHook.transform.position = vector3(440, 115, 0);
	bRightHook.transform.orientation = quaternion(pi/6, vector3::In());

	// Add them to a container
	boardColliders = vector<Bar>();
	boardColliders.push_back(bLeft);
	boardColliders.push_back(bRight);
	boardColliders.push_back(bBase);
	boardColliders.push_back(bShute);
	boardColliders.push_back(bTop);
	boardColliders.push_back(bTopRight);
	boardColliders.push_back(bLeftGuard);
	boardColliders.push_back(bRightGuard);
	boardColliders.push_back(bLeftHook);
	boardColliders.push_back(bRightHook);

	// Get the system frequency
	LARGE_INTEGER li;
	QueryPerformanceFrequency(&li);
	freq = (double)li.QuadPart;
}

int main( int argc, char* argv[] )
{
	// Window Setup
	glutInit( &argc, argv );
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowPosition( 400, 50 );
	glutInitWindowSize( window_width, window_height );
	glutCreateWindow( "Oh look, Pinball!" );

	// Callback functions
	glutReshapeFunc(reshape);
	glutDisplayFunc(displayFunc);
	glutKeyboardFunc(keyboardFunc);
	glutKeyboardUpFunc(keyUpFunc);
	glutMotionFunc(motionFunc);

	glClearColor(0.0, 0.0, 0.0, 1.0);
    glEnable(GL_DEPTH_TEST);

	// Game Setup
	Initialize();

	glutMainLoop();
}	